package com.example.administrator.myappjson;

import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2016/12/6.
 */
public class ResaultJ {

    private String country;
    private String province;
    private String city;

    public String getRes() {

        Gson gson = new Gson();
        ResaultJ resaultJ = new ResaultJ();
        String str = gson.toJson(resaultJ);
//        JSONObject j = new JSONObject();
//
//        try {
//            j.put("country",getCountry());
//            j.put("province",getProvince());
//            j.put("city",getCity());
//
//        }catch (JSONException e) {
//
//        }
//        String string = j.toString();
//        return string;
        return str;
    }

    public static ResaultJ getJSon(String str) {

        ResaultJ r = new ResaultJ();

        try {
            JSONObject object = new JSONObject(str);

            String cou = object.getString("country");
            String pro = object.getString("province");
            String city = object.getString("city");

            r.setCountry(cou);
            r.setProvince(pro);
            r.setCity(city);


        }catch (JSONException e) {

        }
        return r;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }
}
